#include "helper.h"

void create_no_error(struct error_info_t * info)
{
  info->error = 0;
}

void create_error(struct error_info_t * info, char * msg)
{
  info->error = 1;
  strncpy(info->error_message, msg, MAX_ERROR_MESSAGE_LENGTH);
}

void paper_info_error_create(struct paper_info_t * paper_info, char * msg)
{
  paper_info->error = 1;
  strncpy(paper_info->error_message, msg, MAX_ERROR_MESSAGE_LENGTH);
}

void paper_info_create(struct paper_info_t * paper_info, char * author, char * title, char * file_name)
{
  paper_info->error = 0;
  strncpy(paper_info->author, author, MAX_AUTHOR_LENGTH);
  strncpy(paper_info->title, title, MAX_TITLE_LENGTH);
  strncpy(paper_info->file_name, file_name, MAX_FILE_NAME_LENGTH);
}

void print_buffor(char * buffor, int size)
{
  int i; 
  for (i = 0; i < size; i++) {
    printf("%c", buffor[i]);
  }
  printf("\n");
}

void create_block(block_t * block, int paper_id, char * data, int size) 
{
  block->error = 0;
  block->paper_id = paper_id;
  block->size = size;
  if (size > 0) {
    memcpy(block->data, data, (size_t)size);
  }
}

void create_error_block(block_t * block, char * message)
{
  block->error = 1;
  strncpy(block->error_message, message, MAX_ERROR_MESSAGE_LENGTH);
}

void create_block_request(block_request_t * request, int paper_id, int block_id)
{
  request->paper_id = paper_id;
  request->block_id = block_id;
}


